package com.jin.lazytool.customevent;

import com.jin.lazytool.entity.IEvent;
import com.jin.lazytool.entity.InputStringEvent;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.GridPane;

public class CustomInputStringEvent extends CustomEvent{
    private final TextField text = new TextField();

    private InputStringEvent event;

    {
        Tooltip.install(luaButton, new Tooltip("""
                返回对象
                {
                    exeFlag: true, // 是否执行        必须返回
                    time: 0,       // 执行前等待时间  必须返回
                    text: ""       // 输入字符串
                }"""));
    }

    @Override
    public String getName() {
        return "输入字符串";
    }
    @Override
    public void initAddPanel(GridPane grid) {
        grid.addRow(2,new Label("固定字符串"),text);
        grid.addRow(3, luaButton, luaScript);
        grid.addRow(4,new Label("等待时间"),time);
    }

    @Override
    public void initEditPanel(GridPane grid, IEvent event) {
        this.event = (InputStringEvent) event;
        luaScript.setText(this.event.getLua());
        text.setText(this.event.getText());
        time.setValue(this.event.getTime());
        initAddPanel(grid);
    }

    @Override
    public IEvent fullAddIEvent() {
        event = new InputStringEvent();
        event.setText(text.getText());
        event.setLua(luaScript.getText());
        event.setTime(time.getNullDefaultValue());
        return event;
    }

    @Override
    public void fullEditIEvent() {
        event.setText(text.getText());
        event.setLua(luaScript.getText());
        event.setTime(time.getNullDefaultValue());
    }

    @Override
    public Class<? extends IEvent> eventClass() {
        return InputStringEvent.class;
    }
}
